package com.webshop.app.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity implementation class for Entity: Invoice
 * 
 */
@Entity
@NamedQueries({ @NamedQuery(name = "findAllInvoices", query = "select i from Invoice i"),
		@NamedQuery(name = "findByIdInvoices", query = "select i from Invoice i  where i.id = :id")})
public class Invoice implements Serializable {

	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue
	private int id;
	@Column
	private float amount;
	@Temporal(TemporalType.TIMESTAMP)
	private Date date;
	
	@ManyToOne
	@JoinColumn(name="customer_fk")
	private Customer customer;
	
	@OneToMany
	private Set<Order> orders;
	
	private Customer creditCard;
	
	@OneToMany(targetEntity=Item.class, mappedBy = "invoice",
			cascade= CascadeType.ALL, fetch= FetchType.EAGER)
	private Set<Item> itemsInInvoice;
	
	@OneToOne(targetEntity= CreditCard.class, cascade= CascadeType.ALL,
			fetch= FetchType.LAZY)
	@JoinColumn(name= "creditcard_fg")
	private CreditCard  creditcard;
	
	

	@OneToOne(targetEntity= Voucher.class, cascade=CascadeType.ALL,
			fetch = FetchType.LAZY)
	@JoinColumn(name="voucher_fk")
	private Voucher voucher;
	
	public Invoice() {
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public float getAmount() {
		return amount;
	}

	public void setAmount(float amount) {
		this.amount = amount;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	@OneToOne
	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Set<Order> getOrders() {
		return orders;
	}

	public void setOrders(Set<Order> orders) {
		this.orders = orders;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
	public Set<Item> getItemsInInvoice() {
		return itemsInInvoice;
	}

	public void setItemsInInvoice(Set<Item> itemsInInvoice) {
		this.itemsInInvoice = itemsInInvoice;
	}
	
	public CreditCard getCreditcard() {
		return creditcard;
	}

	public void setCreditcard(CreditCard creditcard) {
		this.creditcard = creditcard;
	}

	public Voucher getVoucher() {
		return voucher;
	}

	public void setVoucher(Voucher voucher) {
		this.voucher = voucher;
	}

}
